package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.PickupBulkstockWarehouseEntity;
import com.yuexunit.finance.project.entity.lexicon.ProductTypeEnum;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.StringUtil;

/**
*@version 创建时间：2017年8月1日 下午5:00:06
*@author wenwenlong
*类说明
*/

@Implements(PickupBulkstockWarehouseService.class)
public class PickupBulkstockWarehouseServiceImpl implements PickupBulkstockWarehouseService {

	@Override
	public Long createPickupBulkstockWarehouse(PickupBulkstockWarehouseEntity entity) {
		PersistUtil.insert(entity);
		return entity.getPickupBulkstockId();
	}

	@Override
	public void updatePickupBulkstockWarehouse(PickupBulkstockWarehouseEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public void deletePickupBulkstockWarehouse(Long pickupBulkstockId) {
		PersistUtil.delete(PickupBulkstockWarehouseEntity.class, pickupBulkstockId);
	}

	@Override
	public List<PickupBulkstockWarehouseEntity> inquirePickupBulkstockWarehouseList(Long pickupId, Long financeId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(PickupBulkstockWarehouseEntity.class);
		if (null != pickupId) {
			criteria.add(Restrictions.eq("pickupId", pickupId));
		}
		if (null != financeId) {
			criteria.add(Restrictions.eq("financeId", financeId));
		}
		return PersistUtil.get(criteria);
	}

	@Override
	public List<Long> getPickupIds(String financeNumber, Integer productType, String bulkstockName, Long financeId, String warehouseName) {
		DetachedCriteria criteria = DetachedCriteria.forClass(PickupBulkstockWarehouseEntity.class);
		if(productType !=null && productType !=0){
			criteria.add(Restrictions.eq("productType", ProductTypeEnum.valueOf(productType)));
		}
		if (StringUtil.isNotBlank(financeNumber)) {
			criteria.add(Restrictions.like("financeNumber", "%" + financeNumber + "%"));
		}
		if (StringUtil.isNotBlank(warehouseName)) {
			criteria.add(Restrictions.like("warehouseName", "%" + warehouseName + "%"));
		}
		if (StringUtil.isNotBlank(bulkstockName)) {
			criteria.add(Restrictions.like("bulkstockName", "%" + bulkstockName + "%"));
		}
		if(financeId !=null && financeId !=0){
			criteria.add(Restrictions.eq("financeId", financeId));
		}
		criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("pickupId")));
		return PersistUtil.get(criteria);
	}
}
